//
//  PEBleCmd.h
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/3/28.
//

#import <Foundation/Foundation.h>
#import "RHLocalSettingTypeModel.h"
typedef NS_ENUM(NSUInteger, CmdEnpointType){
    CmdEnpointTypeUnkown   = 255,//未知指令类型
    CmdEnpointTypePack1    = 101,//从机
    CmdEnpointTypePack2    = 102,//从机
    CmdEnpointTypePack3    = 103,//从机
    CmdEnpointTypePack4    = 104,//从机
    CmdEnpointTypePack5    = 105,//从机
    CmdEnpointTypePack6    = 106,//从机
    CmdEnpointTypePack7    = 107,//从机
    CmdEnpointTypePack8    = 108,//从机
    CmdEnpointTypeMaster  = 2,
    CmdEnpointTypeBattery = 3,
    CmdEnpointTypeInveter = 4,
    CmdEnpointTypeDCDC1   = 5,//光伏侧
    CmdEnpointTypeDCDC2   = 6,//逆变器侧
    CmdEnpointTypePCS     = 7,
    CmdEnpointTypeEMS     = 8,
    CmdEnpointTypeEMU     = 20
};
NS_ASSUME_NONNULL_BEGIN

@interface RHBleCmdData : NSObject


/// 读取指定寄存器值
/// - Parameters:
///   - type: 端点类型(设备地址)
///   - addr: 寄存器地址
///   - lengh: 读取多少个寄存器
+(NSData*)buildSingleReadCmdWithEndpointType:(CmdEnpointType)type regAddr:(int)addr byteLength:(int)lengh;


/// 根据模型读取寄存器值
/// - Parameters:
///   - settingModel: 参数模型
///   - type: 端点类型
+(NSData*)buildSingleReadCmdWithSettingModel:(RHLocalSettingModel*)settingModel settingType:(LocalSettingType)type;

///根据 字段 读取寄 多个 器值
+(NSData*)buildMultipleReadCmdWithEndpointType:(CmdEnpointType)type count:(NSInteger)count regAddr:(int)addr;

///根据 模型 读取 多个 寄器值
+(NSData*)buildMultipleReadCmdWithSettingModel:(RHLocalSettingModel*)settingModel settingType:(LocalSettingType)type;



///根据 字段 设置单个寄器值
+(NSData*)buildSingleSetCmdWithEndpointType:(CmdEnpointType)type paraKey:(NSString*)key value:(int)value;

///根据 模型 设置单个寄器值
+(NSData*)buildSingleSetCmdWithSettingModel:(RHLocalSettingModel*)settingModel settingType:(LocalSettingType)type;

//CRC校验
+(uint16_t)CRC_16_MODBUS:(uint8_t*)puchMsg leng:(uint16_t) usDataLen;

//命令类型转设置类型
+(LocalSettingType)toSettingType:(CmdEnpointType)settingType;

+(int)offsetValueWithBitWidth:(int)bitWith;
@end

NS_ASSUME_NONNULL_END
